package cn.xuanxuanyuhua.crm.web.controller;

import cn.xuanxuanyuhua.crm.domain.CustomerTransfer;
import cn.xuanxuanyuhua.crm.domain.Employee;
import cn.xuanxuanyuhua.crm.query.CustomerTransferQueryObject;
import cn.xuanxuanyuhua.crm.query.QueryObject;
import cn.xuanxuanyuhua.crm.service.ICustomerService;
import cn.xuanxuanyuhua.crm.service.ICustomerTransferService;
import cn.xuanxuanyuhua.crm.util.DateUtil;
import cn.xuanxuanyuhua.crm.util.JSONResult;
import cn.xuanxuanyuhua.crm.util.UserContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/customerTransfer")
public class CustomerTransferController {

    @Autowired
    private ICustomerTransferService service;
    @Autowired
    private ICustomerService cService;

    @RequestMapping("/list")
    public String list(Model m,@ModelAttribute("qo")CustomerTransferQueryObject qo){
        Employee activeUser = UserContext.getActiveUser();
        if (!UserContext.isAdminAndMgr()) {
            qo.setSellerId(UserContext.getActiveUser().getId());
        }
        qo.setOrderBy("ct.operateTime desc");
        m.addAttribute("pageInfo",service.query(qo));
        return "/customerTransfer/list";
    }

    @RequestMapping("/save")
    public String  saveOrUpdate(CustomerTransfer entity){
        service.save(entity);
        cService.updateInfo(entity);
        return "redirect:/customerTransfer/list.do";
    }

}
